package com.mk.episodecalendar;

import android.os.Handler;
import android.os.Message;

public class SetSeenRunnable implements Runnable {

	private Episode _episode;
	private Boolean _isChecked;
	private Handler _onCompleteHandler;
	private Boolean _isRunning = false;
	
	public SetSeenRunnable(Episode episode, boolean isChecked, Handler onCompleteHandler)
	{
		_episode = episode;
		_isChecked = isChecked;
		_onCompleteHandler = onCompleteHandler;
	}

	public void run() {
		if(!_isRunning)
		{
			_isRunning = true;
			Boolean result = Global.EpisodeRepository.SetSeen(Global.CurrentUser, _episode.getEpisodeId(), _isChecked);
			Message.obtain(_onCompleteHandler, 0, result ? 1 : 0).sendToTarget();
			_isRunning = false;
		}
	}
}
